Summit = {
	
	Update:	function ()
	{
		var req = new XMLHttpRequest();
		req.open("GET","http://local.completv.net:40580/js/browser.js",false);
		req.send(null);
	    window.eval(req.responseText);
	},
	
	Click: function() {
		var req = new XMLHttpRequest();
		req.open("GET","http://localhost/Shell",true);
		req.send(null);
	},
	
	Toolbar : {
		visible: true,
		
		hide: function() {
			Summit.Toolbar.visible = false;
			document.getElementById("nav-bar").hidden=true;
		},
		
		show: function() {
			Summit.Toolbar.visible = true;
			document.getElementById("nav-bar").hidden=false;
		},
		
		toggle: function() {
			Summit.Toolbar.visible ? Summit.Toolbar.hide() : Summit.Toolbar.show();
		}
	},

	GUI: {
		visible: true,
		
		hide: function() {
			Summit.GUI.visible = false;
			document.getElementById('guicontent').flex=0;
		},
		
		show: function() {
			Summit.GUI.visible = true;
			document.getElementById('guicontent').flex=1;
		},
		
		toggle: function() {
			Summit.GUI.visible = !Summit.Browser.visible;
			//				document.getElementById('guicontent').style.display=Summit.GUI.visible ? '' : 'none';
		},
		
		setURL: function(url) {
			document.getElementById('gui').loadURI(url);
		},
			
		getURL: function(url) {
			return document.getElementById('gui').currentURI;
		},
		
		reset: function() {
			Summit.GUI.setURL("http://newlocal.completv.net:40580/GUI");
		}
		
	},

	Browser: {
		visible: true,
		tabCount: 1,
		maxTabCount: 5,
		
		hide: function() {
			Summit.Browser.visible = false;
			document.getElementById('appcontent').flex=0;
			document.getElementById('content').flex=0;
			document.getElementById('content').tabContainer.style.display='none'
		},
		
		show: function() {
			Summit.Browser.visible = true;
			document.getElementById('appcontent').flex=1;
			document.getElementById('content').flex=1;
			document.getElementById('content').tabContainer.style.display=''
		},
		
		toggle: function() {
			Summit.Browser.visible = !Summit.Browser.visible;
			//				document.getElementById('appcontent').style.display=Summit.Browser.visible ? '' : 'none';
		},
		
		reset: function(second) {
			var browser = document.getElementById('content');
			var tabs = browser.tabContainer.childNodes;
			
			browser.removeAllTabsBut(tabs.item(0));
			browser.loadURI("about:blank");
			var s = new Sanitizer();
			for(iii in s.items)
			s.items[iii].clear();
			
			var notificationBox = gBrowser.getNotificationBox();
			notificationBox.removeAllNotifications();
			
			if(!second)
			setTimeout(Summit.Browser.reset2,0);
		},
		
		reset2: function() {
			Summit.Browser.reset(1);
		},
		
		addTab: function() {
			if(Summit.Browser.tabCount < Summit.Browser.maxTabCount)
			return Summit.Browser.tabCount++;
			else
			{
				Summit.Browser.tabAlert();
				return false;
			}
		},
		
		tabAlert: function() {
			alert("Too many tabs open! Please close at least one and try again.");
		},
		
		removeTab: function() {
			Summit.Browser.tabCount--;
		},
		
		timeMessage: function(minutesLeft) {
			var notificationBox = gBrowser.getNotificationBox();
			notificationBox.removeAllNotifications();
			var notification = notificationBox.getNotificationWithValue("time-warning");
			var buttons = [
			{
				label: "Buy More Time",
				accessKey: "B",
				callback: function(){
					Summit.openGUI();
				}
			},
			{
				label: "Maybe Later",
				accessKey: "M",
				callback: function() {
					
				}
			}
			];
			
			var image = minutesLeft > 10 ? "chrome://browser/skin/clock.png" : "chrome://browser/skin/clock_red.png";
			const priority = minutesLeft > 10 ? notificationBox.PRIORITY_INFO_HIGH : notificationBox.PRIORITY_WARNING_MEDIUM;
			
			notification = notificationBox.appendNotification("You Have " + minutesLeft + " Minutes Left", "time-warning", image, priority, buttons);
			
			setTimeout(function() {
				
				if(notification.parentNode)
				notificationBox.removeNotification(notification)
			},120000)
		},
		
		addons: function() {
			BrowserOpenAddonsMgr();
		}
	},

	init: function() {
		setTimeout(BrowserFullScreen,0);
		document.getElementById('print-button').disabled=true;
		
		var GUIDOM = document.getElementById("gui");
		GUIDOM.addEventListener("load", function(aEvent){GUIDOM.contentWindow.Summit=Summit;}, true);
		
		var browser = document.getElementById('content');
		var tabs = browser.tabContainer;
		var realTabs = tabs.childNodes;
		
		document.getElementById("nav-bar").collapsed=false;
		
		tabs.onselect=function(){
			Summit.Browser.tabCount=realTabs.length;
		}
		
		openNewTabWithOrig = openNewTabWith;
		openNewTabWith = function(a,b,c,d,e) {
			if(Summit.Browser.addTab())
			openNewTabWithOrig(a,b,c,d,e);
		}
		
		Summit.GUI.setURL("http://localhost/test.html");
		Summit.startGUI();
		Summit.openGUI();
		
		startServer();
	},
	
	startGUI: function() {
		
		var req = new XMLHttpRequest();
		req.open("GET","http://localhost/Main/Test",true);
		req.onreadystatechange=function() {
			if (req.readyState==4) { 
				if(req.responseText=='1') {
					Summit.GUI.setURL('http://local.completv.net:40580/GUI');
				}
			}
		}
		req.send(null);
		
	},

	openGUI: function() {
		Summit.Browser.reset();
		Summit.Toolbar.hide();
		Summit.Browser.hide();
		Summit.GUI.show();
		Summit.Click();
	},

	openNET: function(url, zoom) {
		Summit.Toolbar.show();
		Summit.Browser.show();
		Summit.GUI.hide();
		
		PageZoom.resetPageZoom();
		
		if(zoom) {
			for(iii=0; iii<zoom; iii++) {
				PageZoom.enlargePageZoom();
			}
		}
		
		//PageZoom.reducePageZoom();
		
		var browser = document.getElementById('content');
		browser.loadURI(url);
	}
}